package com.leesche.netdoll.communication.protocol.encoder;

import java.util.List;

import org.apache.commons.lang3.ArrayUtils;

import com.leesche.framework.core.lang.ArrayUtil;

public class CommandConfiguration {

	private String[] pattern;

	private List<ParameterConfiguration> parameters;

	private byte[] binary;

	public byte[] pattern() {

		if (ArrayUtil.isNotEmpty(binary)) {
			return binary;
		}

		if (ArrayUtils.isEmpty(pattern)) {
			return null;
		}

		binary = new byte[pattern.length];

		for (int i = 0; i < pattern.length; i++) {
			binary[i] = Byte.decode(pattern[i]);
		}

		return binary;
	}

	public static class ParameterConfiguration {

		private int len;
		private int offset;
		private String encoder;

		public int getOffset() {
			return offset;
		}

		public void setOffset(int offset) {
			this.offset = offset;
		}

		public int getLen() {
			return len;
		}

		public void setLen(int len) {
			this.len = len;
		}

		public String getEncoder() {
			return encoder;
		}

		public void setEncoder(String encoder) {
			this.encoder = encoder;
		}
	}

	public String[] getPattern() {
		return pattern;
	}

	public void setPattern(String[] pattern) {
		this.pattern = pattern;
	}

	public List<ParameterConfiguration> getParameters() {
		return parameters;
	}

	public void setParameters(List<ParameterConfiguration> parameters) {
		this.parameters = parameters;
	}
}
